package com.tianqu.tms.www.car.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAjaxAction;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.entity.VehicleBrand;

/**
 * @author zhangxueliang
 * 高级搜索车辆名称载入（只载入二级）
 */
public class CarLoadBrandAjaxAction extends TmsAjaxAction{

	private Logger logger = Logger.getLogger(CarLoadBrandAjaxAction.class);
	private static final String VENDORID = "vendorId";
	@SuppressWarnings("unchecked")
	@Override
	public void process(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc)throws TmsException {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = TxController.getTxController();
		controller.begin();
		String vendorId = request.getParameter(VENDORID);
		
		VehicleBrand brand = VehicleBrand.getInstance();		
		List list = brand.getAllVehicleBrandInfo(vendorId);
				
		//拼select
		StringBuffer str = new StringBuffer();
		str.append("<select name=\"carBrand\" id=\"carBrand\">");
		
		Map map = null;
		for(int i=0;i<list.size();i++)
		{
			map =(Map)list.get(i);
			str.append("<option value=\""+map.get("brandId")+"\">"+map.get("brandName")+"</option>");
		}
		str.append("</select>");
		
		String responseText =str.toString();
		controller.commit();
		responseValues(response, responseText, TEXT);
		logger.debug(this.getClass().getName() + "#doAction was completed.");		
		
	}

}
